<?php
namespace Home\Controller;

class FeedbackController extends \Home\Controller\BaseController
{
	/**
	 * 用户添加反馈信息
	 * @author 刘新
	 */
	public function add()
	{
		$param = I('params');
		if(!$param['content']) $this->ajaxReturn(array('error' => 1, 'info' => '请输入返馈信息'));

		//添加返馈
		$data['content'] = $param['content'];
		$data['mobile'] = $this->user['mobile'];
		$data['user_id'] = $this->user['userId'];
		$data['create_time'] = NOW_TIME;
		$data['update_time'] = NOW_TIME;
		$data['status'] = 2;
		$data['contact_info'] = $param['contactInfo'];
		$feedback = M('Feedback');
		$res = $feedback->add($data);
		
		//添加失败
		if(!$res) {
			$this->errorLog(__FILE__, __LINE__, $feedback->getDbError() . '---' . $feedback->getError());
			$this->ajaxReturn(array('error' => 1, 'info' => '返馈失败'));
		}
		
		//添加成功
		$this->ajaxReturn(array('error' => 0, 'info' => '返馈成功'));
	}

	/**
	 * 查询返馈列表
	 * @author 刘新
	 */
	public function feedbackList()
	{
		$where = array('user_id' => $this->user['userId'], 'status' => array('gt', -1));
		$feedback = M('Feedback');
		$list = $this->returnList($feedback, $where, 'create_time desc');
		
		//查询失败
		if($list === false) {
			$this->errorLog(__FILE__, __LINE__, $feedback);
			$this->ajaxReturn(array('error' => 1, 'info' => '查询失败'));
		}
		
		//查询成功
		$list = int_to_string($list, array('status' => C('FEEDBACK')));
		$return = $this->successResult($list);
		$this->ajaxReturn($return);
	}
}